USACO 1.1 Friday the Thirteenth

/*
ID: aznfy1
PROG: friday
LANG: C++
*/

#include<stdio.h>
#include<string.h>
#include<iostream>
#define clr(a,b); memset(a,b,sizeof(a));

using namespace std;

int dayofmonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int week[7];

int isleap(int x)
{
    if(x%4==0&&x%100!=0)
    return 1;
    else if(x%400==0)
    return 1;
    else
    return 0;

}

int main()
{
    freopen("friday.in","r",stdin);
    freopen("friday.out","w",stdout);

    int n;
    while(cin>>n)
    {
        int t=0;
        clr(week,0);
        for(int i=1900;i<1900+n;i++)
        {
            if(isleap(i))
            dayofmonth[2]=29;
            else
            dayofmonth[2]=28;
            for(int j=1;j<=12;j++)
            {
                week[(t+13)%7]++;
                t+=dayofmonth[j];
            }

        }
        cout<<week[6]<<' '<<week[0]<<' ';
        for(int i=1;i<=4;i++)
        {
            cout<<week[i]<<' ';
        }
        cout<<week[5]<<endl;
    }
    return 0;
}
View Code

 

posted on 2013-05-15 22:56  Fray  阅读(157)  评论(0编辑  收藏  举报

导航